package controllers

import (
	"github.com/astaxie/beego"
	//"fmt"
	//"database/sql"
	_ "github.com/mattn/go-sqlite3"
	 "beego/testApp/common/user"
	 "beego/testApp/common/tool"
	 
)

type LoginController struct {
	beego.Controller
}

func (c *LoginController) Get() {

		username := c.GetString("username");
		pass  := c.GetString("pass");


		if(username!="" && pass!="" ){
			//fmt.Println("login admin")
			loginstatus := user.Login(username,pass)
			
			//re := user.List(1,10)
			
			//tool.Pic("userlist",re)

			if(loginstatus == true){

				c.SetSession("username",username)
				c.Redirect("/admin", 302)
				return 
			}
		}   

		//user.Adduser("admin","admin")

		ckAdminEmpty := user.CkAdminUserExist()

		if( ckAdminEmpty == false ){
			user.Adduser("admin","admin")
		}

		tool.Pic("no user ",username+" "+pass)
		c.TplName = "login.tpl"
	
}

